package team.stride.database.crud.imported;

import java.util.List;

import team.stride.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImportedAdapter extends BaseAdapter
{
	private BDImportedActivity activity;
	private List<ImportedItem> importedList;

	public ImportedAdapter(BDImportedActivity activity, List<ImportedItem> mapslist)
	{
		this.activity = activity;
		this.importedList = mapslist;
	}

	public int getCount()
	{
		return importedList.size();
	}

	public ImportedItem getItem(int position)
	{
		return importedList.get(position);
	}

	public long getItemId(int position)
	{
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup viewGroup)
	{
		final ImportedItem entry = importedList.get(position);
		if (convertView == null)
		{
			LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.bd_imported_row, null);
		}
		
		TextView importedName = (TextView) convertView.findViewById(R.id.importedName);
		importedName.setText(entry.getName());

		TextView importedUsername = (TextView) convertView.findViewById(R.id.importedUsername);
		importedUsername.setText("" + entry.getUsername());

		TextView importedLength= (TextView) convertView.findViewById(R.id.importedLength);
		importedLength.setText("" + entry.getLength() + " Km");

		TextView importedDate = (TextView) convertView.findViewById(R.id.importedDate);
		importedDate.setText("" + entry.getDate());
		
		TextView importedTime= (TextView) convertView.findViewById(R.id.importedTime);
		importedTime.setText("" + entry.getTime() + " sec");
		
		TextView importedSpeed = (TextView) convertView.findViewById(R.id.importedSpeed);
		importedSpeed.setText("" + entry.getTopSpeed() + " Km/h");

		
		TextView importedDetails = (TextView) convertView.findViewById(R.id.importedDetails);
		importedDetails.setText("" + entry.getDetails());

		ImageView importedImg = (ImageView) convertView.findViewById(R.id.importedImg);
		importedImg.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				activity.showDialog(BDImportedActivity.MODIFY_DIALOG, entry);
			}
		});
		return convertView;
	}
}
